<?php
echo validation_errors();
$form = array(
    'id'    => 'form-fixture',
    'class' => 'span6 ut-form no-gutter row'
);
$time = array(
    '18:00'=>'18:00',
    '18:30'=>'18:30',
    '19:00'=>'19:00',
    '19:30'=>'19:30',
    '20:00'=>'20:00',
    '20:30'=>'20:30',
    '21:00'=>'21:00',
    '21:30'=>'21:30',
    '22:00'=>'22:00',
    '22:30'=>'22:30',
    '23:00'=>'23:00',
    '23:30'=>'23:30',
    '00:00'=>'00:00'
);
foreach($teams as $team)
    foreach($team['teams'] as $ti=>$tv)
        $options[$ti] = $tv;
echo form_open('league/insert_fixture',$form);
echo form_hidden('fid',$fixture['fixture']['number']);
echo form_hidden('lid',$fixture['fixture']['league_id']);
echo form_hidden('sid',$fixture['fixture']['game_season']);
echo form_fieldset();
$nr_teams = count($options);
$nr_games = ($nr_teams - ($nr_teams%2))/2;
$i = 0;
?>
<div class="row span8">
    <?php 
    foreach($fixture['fixture']['games'] as $game)
    {
        echo '<div class="span4 no-gutter">'.form_label('Godzina początkowa: ','hour').form_dropdown('hour',$time,$game['time'],'id="time_picker" class="tiny"').'</div>';
        break;
    }
    ?>
    <div class="span4"><?php echo form_label('Data kolejki: ','fixt_date'); ?><input type="date" name="fixt_date" class="small ut-datepicker" value="<?php echo set_value('fixt_date',date('Y-m-d',$fixture['fixture']['fixture_date'])); ?>" id="fixt-datepicker" placeholder="RRRR-MM-DD"/></div>
</div>
<table class="table table-striped table-condensed span6">
    <thead>
        <tr>
            <th>Gospodarz</th>
            <th colspan="3" style="text-align: center;">Wynik</th>
            <th>Gość</th>
            <th>Godzina</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($fixture['fixture']['games'] as $gi=>$game): ?>
            <tr>
                <td><?php echo form_dropdown('gosp['.$i.']',$options,set_value('gosp['.$i.']',$game['teams']['gosp']['id'])); ?></td>
                <td class="micro"><?php echo form_input('gosp-gol['.$i.']',set_value('gosp['.$i.']',$game['teams']['gosp']['score']),'class="micro" maxlength="2"'); ?></td>
                <td>:</td>
                <td class="micro"><?php echo form_input('gosc-gol['.$i.']',set_value('gosc['.$i.']',$game['teams']['gosc']['score']),'class="micro" maxlength="2"'); ?></td>
                <td><?php echo form_dropdown('gosc['.$i.']',$options,set_value('gosc['.$i.']',$game['teams']['gosc']['id'])); ?></td>
                <td class="tiny"><?php echo form_input('godz['.$i.']',set_value('godz['.$i.']',$game['time']),'class="tiny time_input" maxlength="5"').form_hidden('gid[]',$gi); ?></td>
            </tr>
        <?php $i++;
        endforeach; ?>
    </tbody>
</table>
<?php
echo '<p class="clear">'.form_submit('update_fixture','Zapisz zmiany','class="btn-primary btn-large"').'</p>';
echo form_fieldset_close();
echo form_close();
?>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
